# create separate DF for OLS analyses
olsdf <- ESS10 %>% 
  filter(date > -15 & date < 15)

olsdf$treat <- NA
olsdf$treat[olsdf$date > -1] <- 1
olsdf$treat[olsdf$date < 0] <- 0
table(olsdf$treat)



## 14 day bandwidth
ols_mig14 <- lm(mig ~ treat, data = olsdf)
summary(ols_mig14)

ols_eco14 <- lm(eco ~ treat, data = olsdf)
summary(ols_eco14)

ols_cul14 <- lm(cul ~ treat, data = olsdf)
summary(ols_cul14)



## 7 day bandwidth

olsdf7 <- olsdf %>% 
  filter(date > -8 & date < 8)

ols_mig7 <- lm(mig ~ treat, data = olsdf7)
summary(ols_mig7)

ols_eco7 <- lm(eco ~ treat, data = olsdf7)
summary(ols_eco7)

ols_cul7 <- lm(cul ~ treat, data = olsdf7)
summary(ols_cul7)




## 3 day bandwidth

olsdf3 <- olsdf %>% 
  filter(date > -4 & date < 4)

ols_mig3 <- lm(mig ~ treat, data = olsdf3)
summary(ols_mig3)

ols_eco3 <- lm(eco ~ treat, data = olsdf3)
summary(ols_eco3)

ols_cul3 <- lm(cul ~ treat, data = olsdf3)
summary(ols_cul3)


# Generate the LaTeX tables
stargazer(
  ols_mig14, ols_eco14, ols_cul14,
  type = "latex",
  title = "Regression Results for 14-Day Bandwidth",
  dep.var.labels = c("Overall", "Economy", "Culture"),
  covariate.labels = c("Treatment Dummy"),
  single.row = TRUE,
  digits = 3,
  font.size = "small",
  label = "tab:regression_14day",
  out = "regression_14day.tex"
)


stargazer(
  ols_mig7, ols_eco7, ols_cul7,
  type = "latex",
  title = "Regression Results for 7-Day Bandwidth",
  dep.var.labels = c("Overall", "Economy", "Culture"),
  covariate.labels = c("Treatment Dummy"),
  single.row = TRUE,
  digits = 3,
  font.size = "small",
  label = "tab:regression_7day",
  out = "regression_7day.tex"
)

stargazer(
  ols_mig3, ols_eco3, ols_cul3,
  type = "latex",
  title = "Regression Results for 3-Day Bandwidth",
  dep.var.labels = c("Overall", "Economy", "Culture"),
  covariate.labels = c("Treatment Dummy"),
  single.row = TRUE,
  digits = 3,
  font.size = "small",
  label = "tab:regression_3day",
  out = "regression_3day.tex"
)


## interaction with news consumption

ols_mig14_int <- lm(mig ~ treat + nwspol + treat*nwspol, data = olsdf)
summary(ols_mig14_int)

ols_eco14_int <- lm(eco ~ treat + nwspol + treat*nwspol, data = olsdf)
summary(ols_eco14_int)

ols_cul14_int <- lm(cul ~ treat + nwspol + treat*nwspol, data = olsdf)
summary(ols_cul14_int)

stargazer(
  ols_mig14_int, ols_eco14_int, ols_cul14_int,
  type = "latex",
  title = "Treatment dummy interacted with news consumption levels",
  dep.var.labels = c("Overall", "Economy", "Culture"),
  single.row = TRUE,
  digits = 3,
  font.size = "small",
  label = "tab:regression_int",
  out = "regression_int.tex"
)



## excluding potentially pre-treated respondents three days ahead of the takeover

olsdf_ex <- olsdf %>% 
  filter(date < -3 | date > -1)


ols_mig14_ex <- lm(mig ~ treat, data = olsdf_ex)
summary(ols_mig14_ex)

ols_eco14_ex <- lm(eco ~ treat, data = olsdf_ex)
summary(ols_eco14_ex)

ols_cul14_ex <- lm(cul ~ treat, data = olsdf_ex)
summary(ols_cul14_ex)


stargazer(
  ols_mig14_ex, ols_eco14_ex, ols_cul14_ex,
  type = "latex",
  title = "Compound treatment (excluding respondents up to 3 days ahead of the takeover)",
  dep.var.labels = c("Overall", "Economy", "Culture"),
  covariate.labels = c("Compound Treatment Dummy"),
  single.row = TRUE,
  digits = 3,
  font.size = "small",
  label = "tab:regression_ex",
  out = "regression_ex.tex"
)

